#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const double alpha = 0.7;

int n, K;
struct KD {
  int sz;
  int w, sum;
  int ch[2];
  int v[2], L[2], U[2];
} tr[N];
#define sz(p) tr[p].sz
#define w(p) tr[p].w
#define sum(p) tr[p].sum
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
#define v(p, k) tr[p].v[k]
#define L(p, k) tr[p].L[k]
#define U(p, k) tr[p].U[k]
int root, cur;
int x1, _y1, x2, y2;
int ans;
int g[N], top;

bool cmp(int x, int y) { return v(x, K) < v(y, K); }
void pushup(int p) {
  sz(p) = sz(lc(p)) + sz(rc(p)) + 1;
  sum(p) = sum(lc(p)) + sum(rc(p)) + w(p);
  rep(k, 0, 1) {
    L(p, k) = U(p, k) = v(p, k);
    if (lc(p)) {
      L(p, k) = min(L(p, k), L(lc(p), k));
      U(p, k) = max(U(p, k), U(lc(p), k));
    }
    if (rc(p)) {
      L(p, k) = min(L(p, k), L(rc(p), k));
      U(p, k) = max(U(p, k), U(rc(p), k));
    }
  }
}
int build(int k, int l, int r) {
  if (l > r) return 0;
  int m = (l + r) >> 1;
  K = k;
  nth_element(g + l, g + m, g + r + 1, cmp);
  lc(g[m]) = build(k ^ 1, l, m - 1);
  rc(g[m]) = build(k ^ 1, m + 1, r);
  pushup(g[m]);
  return g[m];
}
void dfs(int p) {
  if (!p) return;
  g[++top] = p;
  dfs(lc(p)), dfs(rc(p));
}
void check(int k, int &p) {
  if (alpha * sz(p) < max(sz(lc(p)), sz(rc(p))))
    top = 0, dfs(p), p = build(k, 1, top);
}
void insert(int k, int &p) {
  if (!p) {
    p = cur;
    pushup(p);
    return;
  }
  insert(k ^ 1, v(cur, k) <= v(p, k) ? lc(p) : rc(p));
  pushup(p);
  check(k, p);
}
int query(int p) {
  if (!p) return 0;
  if (x1 > U(p, 0) || x2 < L(p, 0) || _y1 > U(p, 1) || y2 < L(p, 1)) return 0;
  if (x1 <= L(p, 0) && x2 >= U(p, 0) && _y1 <= L(p, 1) && y2 >= U(p, 1))
    return sum(p);
  int res = 0;
  if (x1 <= v(p, 0) && x2 >= v(p, 0) && _y1 <= v(p, 1) && y2 >= v(p, 1))
    res += w(p);
  return query(lc(p)) + query(rc(p)) + res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  int op;
  while (cin >> op) {
    if (op == 3) break;
    if (op == 1) {
      cur++;
      cin >> v(cur, 0) >> v(cur, 1) >> w(cur);
      v(cur, 0) ^= ans;
      v(cur, 1) ^= ans;
      w(cur) ^= ans;
      insert(0, root);
      int cnt = sz(root);
    }
    if (op == 2) {
      cin >> x1 >> _y1 >> x2 >> y2;
      x1 ^= ans, x2 ^= ans, _y1 ^= ans, y2 ^= ans;
      ans = query(root);
      cout << ans << endl;
    }
  }
  return 0;
}